package com.example.qxfw.dataBaseManager.Controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.Roles;
import com.example.qxfw.common.entity.ny.Log;
import com.example.qxfw.common.entity.xt.Permissions;
import com.example.qxfw.common.util.EasyExcelUtil;
import com.example.qxfw.dataBaseManager.service.SystemManagerservice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/7  星期五   11:40
 * @description : 此类用来  系统管理
 ***************************************/
@ApiIgnore
@Slf4j
@Api(tags = "数据库管理-系统管理")
@RestController
@CrossOrigin
@RequestMapping("/SystemManagerController")
public class SystemManagerController {

    @Autowired
    private SystemManagerservice systemManagerservice;

    @ApiOperation("模糊查询")
    @GetMapping("querySelect")
    public SysResult querySelect(String startTime, String endTime, String userName) {
        List<Log> logList = this.systemManagerservice.querySelect(startTime, endTime, userName);
        return SysResult.success(logList);
    }

    @ApiOperation("批量删除")
    @RequestMapping("deleteLogByIdList")
    public SysResult deleteLogByIdList(List<String> idList) {
        Integer integer = this.systemManagerservice.deleteLogByIdList(idList);
        return SysResult.success(integer);
    }

    @ApiOperation("清空")
    @RequestMapping("clearLog")
    public SysResult clearLog() {
        Integer integer = this.systemManagerservice.clearLog();
        return SysResult.success(integer);
    }


    @GetMapping("/exportLog")
    public SysResult exportLog(HttpServletResponse response) throws IOException {
        List<Log> all = this.systemManagerservice.getAllLog();
        if (all.size() > 0) {
            EasyExcelUtil.exportDataToExcel(response, "日志信息", "模板", all, Log.class);
            return SysResult.success(all);
        } else {
            return SysResult.fail("没有数据");
        }
    }

    @RequestMapping(value = "getAllRoles",method = RequestMethod.GET)
    public SysResult getAllRoles(){
        List<Roles> allRoles = this.systemManagerservice.getAllRoles();
        return SysResult.success(allRoles);
    }

    @RequestMapping(value = "getAllPermissions",method = RequestMethod.GET)
    public SysResult getAllPermissions(){
        List<Permissions> allPermissions = this.systemManagerservice.getAllPermissions();
        return SysResult.success(allPermissions);
    }









}
